<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>原型链的继承方式</title>
</head>
<body>
    <script>
        /**
        * 原型链继承
        * 缺陷：引用值共享
        **/
        console.log([]);
        // [] - Array.prototype - Object.prototype
        // [] - [].__proto__ - [].__proto__.__proto__
        
        function Supper() {
            this.a = '111';
            this.b = [1, 2, 3, 4]
        }

        Supper.prototype = {
            say: function(){
                console.log('222');
            }
        }

        function Sub() {}

        Sub.prototype = new Supper();

        var sub1 = new Sub();
        console.log(sub1);
        // sub1 -> Sub.prototype(new Supper()) -> Supper.prototype

        // console.log(sub1.a);
        sub1.a = '333';
        sub1.b.push(5)
        sub1.say();

        var sub2 = new Sub();

        console.log(sub1.a); // 333
        console.log(sub2.a); // 111

        // 原型链继承的缺陷（引用值共享的问题）
        console.log(sub1.b); // [1, 2, 3, 4, 5]
        console.log(sub2.b); // [1, 2, 3, 4, 5] 
    </script>
</body>
</html>